package org.farng.mp3.id3;

import org.farng.mp3.InvalidTagException;
import org.farng.mp3.object.ObjectByteArraySizeTerminated;
import org.farng.mp3.object.ObjectNumberFixedLength;
import org.farng.mp3.object.ObjectStringNullTerminated;

import java.io.IOException;


/**
 * DOCUMENT ME!
 *
 * @author Eric Farng
 * @version $Revision: 1.3 $
 */
public class FrameBodyAENC extends AbstractID3v2FrameBody {
    /**
     * Creates a new FrameBodyAENC object.
     */
    public FrameBodyAENC() {
        //        this.setObject("Owner", "");
        //        this.setObject("Preview Start", new Short((short) 0));
        //        this.setObject("Preview Length", new Short((short) 0));
        //        this.setObject("Encryption Info", new byte[0]);
    }

    public FrameBodyAENC(FrameBodyAENC body) {
        super(body);
    }

    /**
     * Creates a new FrameBodyAENC object.
     *
     * @param owner DOCUMENT ME!
     * @param previewStart DOCUMENT ME!
     * @param previewLength DOCUMENT ME!
     * @param data DOCUMENT ME!
     */
    public FrameBodyAENC(String owner, short previewStart, short previewLength, byte[] data) {
        this.setObject("Owner", owner);
        this.setObject("Preview Start", new Short(previewStart));
        this.setObject("Preview Length", new Short(previewLength));
        this.setObject("Encryption Info", data);
    }

    /**
     * Creates a new FrameBodyAENC object.
     *
     * @param file DOCUMENT ME!
     *
     * @throws IOException DOCUMENT ME!
     * @throws InvalidTagException DOCUMENT ME!
     */
    public FrameBodyAENC(java.io.RandomAccessFile file)
                  throws IOException, InvalidTagException {
        this.read(file);
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getIdentifier() {
        return "AENC" + ((char) 0) + getOwner();
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getOwner() {
        return (String) getObject("Owner");
    }

    /**
     * DOCUMENT ME!
     *
     * @param description DOCUMENT ME!
     */
    public void getOwner(String description) {
        setObject("Owner", description);
    }

    /**
     * DOCUMENT ME!
     */
    protected void setupObjectList() {
        objectList.add(new ObjectStringNullTerminated("Owner"));
        objectList.add(new ObjectNumberFixedLength("Preview Start", 2));
        objectList.add(new ObjectNumberFixedLength("Preview Length", 2));
        objectList.add(new ObjectByteArraySizeTerminated("Encryption Info"));
    }
}